﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Security;
using SchoolProject2012.Areas.Eleve.Models;
using SchoolProject2012.Functions;

namespace SchoolProject2012.Areas.Eleve.Controllers
{
    public class AgendaController : Controller
    {
        private EleveSchoolProjectBddEntities db = new EleveSchoolProjectBddEntities();
        //
        // GET: /Eleve/Agenda/

        [Authorize(Roles = "Eleve, Admin, BDE, Delegue")]
        public ActionResult Index(string langue)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            ViewBag.langue = langue;
            return View();
        }

        [Authorize(Roles = "Eleve, Admin, BDE, Delegue")]
        public ViewResult Cours()
        {
            string login = Session["login"].ToString();
            string year = Utils.getCurrentYearForClass();
            int classe = db.ELEVECLASS.Single(x => x.ELEVE.LOGINPERS == login && x.CLASSE.ANNEECLASSE == year).IDCLASS;
            var cours = db.COURS.Where(x => x.MODULE.CLASSE.IDCLASSE == classe).ToList();
            return View(cours);
        }

        private String getCurrentYearForClass()
        {
            DateTime today = new DateTime();
            if (today.Month > 8)
                return today.Year.ToString() + "/" + (today.Year + 1).ToString();
            else
                return (today.Year - 1).ToString() + "/" + today.Year.ToString();
        }

    }
}
